<!--
 * @Description: Description
 * @Author: Yongchao Wang
 * @Date: 2020-09-10 08:37:58
 * @LastEditors: Yongchao Wang
 * @LastEditTime: 2020-09-11 06:57:53
-->
<template>
<!-- optionAPI -->
  <div class="hello">
    <input type="number" v-model="num1" @keyup="add">
    <span>+</span>
    <input type="number" v-model="num2" @keyup="add">
    <span>=</span>
    {{result}}
  </div>

<!-- Composition API reactive computed-->
  <div>
    <input type="number" v-model="state.num3" @keyup="add1">
    <span>+</span>
    <input type="number" v-model="state.num4" @keyup="add1">
    <span>=</span>
    {{state.result1}}
  </div>
</template>

<script>
import {computed, reactive} from 'vue'
const state =  reactive({
  num3:0,
  num4:0,
  result1:computed(()=>parseInt(state.num3)+ parseInt(state.num4))})
function add1(){
  state.result1 = parseInt(state.num3)+ parseInt(state.num4)
}
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  data() {
    return {
      num1:0,
      num2:0,
      result:0
    }
  },
  computed:{
    result(){
      return parseInt(this.num1) + parseInt(this.num2)
    }
  },
// Composition API reactive computed
  setup(){
    return {
      state
    }
  },
  methods: {
    
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
